﻿using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using Google.Protobuf;
using Google.Protobuf.Reflection;

namespace EggLink.DanhengServer.Proto
{
    // 服务器区域信息协议类（Protobuf生成）
    [DebuggerDisplay("{ToString(),nq}")]
    public sealed class RegionInfo : IMessage<RegionInfo>, IMessage, IEquatable<RegionInfo>, IDeepCloneable<RegionInfo>, IBufferMessage
    {
        // Protobuf解析器静态实例
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public static MessageParser<RegionInfo> Parser { get { return _parser; } }

        // Protobuf消息描述符（反射用）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public static MessageDescriptor Descriptor { get { return RegionInfoReflection.Descriptor.MessageTypes[0]; } }

        // 显式接口实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        MessageDescriptor IMessage.Descriptor { get { return Descriptor; } }

        // 默认构造函数
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public RegionInfo () { }

        // 拷贝构造函数（深拷贝）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public RegionInfo (RegionInfo other) : this()
        {
            name_ = other.name_;
            title_ = other.title_;
            dispatchUrl_ = other.dispatchUrl_;
            envType_ = other.envType_;
            displayName_ = other.displayName_;
            msg_ = other.msg_;
            _unknownFields = UnknownFieldSet.Clone(other._unknownFields);
        }

        // 克隆方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public RegionInfo Clone () { return new RegionInfo(this); }

        // 区域唯一标识字段（如"cn_gf01"）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string Name
        {
            get { return name_; }
            set { name_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 区域标题字段（可能用于后台管理）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string Title
        {
            get { return title_; }
            set { title_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 调度服务器URL字段（如"http://127.0.0.1/query_gateway"）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string DispatchUrl
        {
            get { return dispatchUrl_; }
            set { dispatchUrl_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 环境类型字段（可能值："0"=开发，"1"=测试，"2"=生产）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string EnvType
        {
            get { return envType_; }
            set { envType_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 显示名字段（玩家可见的服务器名称）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string DisplayName
        {
            get { return displayName_; }
            set { displayName_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 附加消息字段（可能用于维护公告）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string Msg
        {
            get { return msg_; }
            set { msg_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 对象比较方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override bool Equals (object other) { return Equals(other as RegionInfo); }

        // 强类型比较方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public bool Equals (RegionInfo other)
        {
            return other != null &&
                   (ReferenceEquals(this, other) ||
                   (Name == other.Name &&
                    Title == other.Title &&
                    DispatchUrl == other.DispatchUrl &&
                    EnvType == other.EnvType &&
                    DisplayName == other.DisplayName &&
                    Msg == other.Msg &&
                    object.Equals(_unknownFields, other._unknownFields)));
        }

        // 哈希码生成
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override int GetHashCode ()
        {
            int hash = 1;
            if (Name.Length != 0) hash ^= Name.GetHashCode();
            if (Title.Length != 0) hash ^= Title.GetHashCode();
            if (DispatchUrl.Length != 0) hash ^= DispatchUrl.GetHashCode();
            if (EnvType.Length != 0) hash ^= EnvType.GetHashCode();
            if (DisplayName.Length != 0) hash ^= DisplayName.GetHashCode();
            if (Msg.Length != 0) hash ^= Msg.GetHashCode();
            if (_unknownFields != null) hash ^= _unknownFields.GetHashCode();
            return hash;
        }

        // JSON格式化输出（调试用）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override string ToString () { return JsonFormatter.ToDiagnosticString(this); }

        // Protobuf序列化方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void WriteTo (CodedOutputStream output) { output.WriteRawMessage(this); }

        // 底层序列化实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        void IBufferMessage.InternalWriteTo (ref WriteContext output)
        {
            if (Name.Length != 0)
            {
                output.WriteRawTag(10);
                output.WriteString(Name);
            }
            if (Title.Length != 0)
            {
                output.WriteRawTag(18);
                output.WriteString(Title);
            }
            if (DispatchUrl.Length != 0)
            {
                output.WriteRawTag(26);
                output.WriteString(DispatchUrl);
            }
            if (EnvType.Length != 0)
            {
                output.WriteRawTag(34);
                output.WriteString(EnvType);
            }
            if (DisplayName.Length != 0)
            {
                output.WriteRawTag(42);
                output.WriteString(DisplayName);
            }
            if (Msg.Length != 0)
            {
                output.WriteRawTag(50);
                output.WriteString(Msg);
            }
            if (_unknownFields != null)
            {
                _unknownFields.WriteTo(ref output);
            }
        }

        // 计算序列化后的字节大小
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public int CalculateSize ()
        {
            int size = 0;
            if (Name.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(Name);
            if (Title.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(Title);
            if (DispatchUrl.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(DispatchUrl);
            if (EnvType.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(EnvType);
            if (DisplayName.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(DisplayName);
            if (Msg.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(Msg);
            if (_unknownFields != null) size += _unknownFields.CalculateSize();
            return size;
        }

        // 反序列化方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void MergeFrom (CodedInputStream input) { input.ReadRawMessage(this); }

        // 底层反序列化实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        void IBufferMessage.InternalMergeFrom (ref ParseContext input)
        {
            uint tag;
            while ((tag = input.ReadTag()) != 0)
            {
                switch (tag)
                {
                    case 10:
                        Name = input.ReadString();
                        break;
                    case 18:
                        Title = input.ReadString();
                        break;
                    case 26:
                        DispatchUrl = input.ReadString();
                        break;
                    case 34:
                        EnvType = input.ReadString();
                        break;
                    case 42:
                        DisplayName = input.ReadString();
                        break;
                    case 50:
                        Msg = input.ReadString();
                        break;
                    default:
                        _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                        break;
                }
            }
        }

        // 对象合并方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void MergeFrom (RegionInfo other)
        {
            if (other == null) return;
            if (other.Name.Length != 0) Name = other.Name;
            if (other.Title.Length != 0) Title = other.Title;
            if (other.DispatchUrl.Length != 0) DispatchUrl = other.DispatchUrl;
            if (other.EnvType.Length != 0) EnvType = other.EnvType;
            if (other.DisplayName.Length != 0) DisplayName = other.DisplayName;
            if (other.Msg.Length != 0) Msg = other.Msg;
            _unknownFields = UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        // 私有字段（严格保持原始声明顺序）
        private static readonly MessageParser<RegionInfo> _parser = new MessageParser<RegionInfo>(() => new RegionInfo());
        private UnknownFieldSet _unknownFields;
        private string name_ = "";
        private string title_ = "";
        private string dispatchUrl_ = "";
        private string envType_ = "";
        private string displayName_ = "";
        private string msg_ = "";
    }
}